package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Dto.DishDto;
import com.itheima.reggie.Dto.DishUpdateDto;
import com.itheima.reggie.Dto.QueryListDto;
import com.itheima.reggie.common.Result;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 * @author Yan
 * @date 2022/2/26
 */
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    public Result<String> saveWithFlavor(@RequestBody DishDto dishDto){
        return dishService.saveWithFlavor(dishDto);
    }


    @GetMapping("/page")
    public Result<Page<QueryListDto>> findDishPage(Long page, Long pageSize, String name){

        return dishService.findDishPage(page,pageSize,name);
    }

    @GetMapping("/{id}")
    public Result<DishUpdateDto> findDishById(@PathVariable Long id){
        return dishService.findDishById(id);
    }

    @PutMapping
    public Result<String> updateDish(@RequestBody DishUpdateDto dishUpdateDto){
        return dishService.updateDish(dishUpdateDto);

    }

    @GetMapping("list")
    public Result<List<DishDto>> listByCategoryId(Long categoryId,Integer status){
        return dishService.listByCategoryId(categoryId,status);
    }


    @DeleteMapping
    public Result<String> deleteDishByList(@RequestParam List<Long> ids){
        return dishService.deleteDishByList(ids);
    }


    /**
     * 菜品起售和停售
     * @param status
     * @param ids
     * @return
     */
    @PostMapping("status/{status}")
    public Result<String> dishStatus(@PathVariable Integer status,@RequestParam List<Long> ids){
        return dishService.dishStatus(status,ids);
    }


}
